package com.pw.study.mr.letter;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Counter;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class MapperByLetter extends Mapper<LongWritable, Text,Text, IntWritable> {
    Counter success;
    Counter fail;
    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
         success= context.getCounter("mpHello", "mpSuccess");
       fail = context.getCounter("mpHello", "mpFail");
    }

    private Text kk = new Text();
private IntWritable one = new IntWritable(1);
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] lines = value.toString().split(" ");
        if(key.get()==0){
            System.out.println("首行不做处理........");
            fail.increment(1);
        }else{
            for (String line : lines) {
                kk.set(line);
                context.write(kk,one);
                success.increment(1);
            }
        }

    }
}
